<template>
  <div class="home-container f_c_m_c">
    <div class="content" v-for="item in List">
      <div class="goods f_c_c_c ">
        <goodsList
          :item="item"
          :time="item.interval"
          pageBargain="1"
          @click="goDetail"
        ></goodsList>
      </div>
      <div class="font-24 color_999 mt-10">开砍时间：{{ item.created_at }}</div>
    </div>
    <div class="unList f_c_c_c" v-if="!List.length">
      <img :src="un_record_img" alt="">
      <span class="font-20 color_999">暂无砍价记录~</span>
    </div>
    <div v-if="popupShow">
      <popupMore
        v-model="popupShow"
        :type="popupType"
        @sub="popupSub"
      ></popupMore>
    </div>
  </div>
</template>

<script>
import goodsList from "@/components/goodsList";
import { record,award } from "@/api/goods";
import getPriceCommon from "@/utils/getPriceCommon";

import un_record_img from "@/assets/un_record.png";


export default {
  name: "record",
  components: { goodsList },
  data() {
    return {
      un_record_img,
      goodsInfo:{},
      List: [],
      popupShow: false,
      popupType: 0,
    };
  },
    computed: {
    code() {
      return this.$store.getters.code;
    },
  },
  mounted() {
    this.getList();
  },
  methods: {
    ...getPriceCommon,
    goDetail(item) {
      this.goodsInfo = item || this.goodsInfo
      let { g_id = "",good_id, g_o_id = "", type, good_type } = item;
      if (type == 1) {
        this.getPrice()
        return;
      }
      //再次挑战
      if(item.status == 3){
        g_o_id = ''
      }
      this.$router.push({
        path: "/detailRed",
        query: { g_id: g_id || good_id, g_o_id: g_o_id },
      });
    },
    getList() {
      record().then((res) => {
        let list = res.data.data;
        if (list && list.length > 0) {
          list.forEach((val, index) => {
            list[index].startTime = val.created_at.slice(0, 16);
            list[index].type = val.status;
            list[index].g_id = val.good_id;
            list[index].g_o_id = val.id;
            val.btn_bac_type = val.status + 1;
            val.interval = this.countTime(val);
          });
        }
        this.List = list;
      });
    },
    countTime(item) {
      let { valid_time } = item;
      let now = Math.round(new Date() / 1000);
      let interval = valid_time - now;
      interval = interval < 0 ? 0 : interval;
      return interval;
      // 倒计时结束，更改界面状态
      if (interval === 0) {
      }
    },
  },
};
</script>

<style scoped lang="scss">
.home-container {
  position: relative;
  background-color: #f0f0f0;
  .content {
    width: 672px;
    padding: 20px;
    box-sizing: border-box;
    flex-shrink: 1;
    background: #ffffff;
    border-radius: 24px;
    margin-top: 30px;
    > .goods {
      width: 100%;
      border-bottom: 1px solid #f5f5f5;
    }
  }
}
</style>
